﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Web;
using Ext.Net;
using Sharp.Infrastructure.Search;
namespace Sharp.Web
{
    [DataContract]
    public class ExtPagingFeature
    {
        private readonly PagingFeature _pf = new PagingFeature(UIEngine.Ext);
        public ExtPagingFeature(StoreRequestParameters parameter)
        {
            _pf.SimpleSort = string.Format("{0} {1}", parameter.SimpleSort, parameter.SimpleSortDirection);
            _pf.PageNo = parameter.Page;
            _pf.PageSize = parameter.Limit;

            var Params = new NameValueCollection
            {
                HttpContext.Current.Request.Form,
                HttpContext.Current.Request.QueryString
            };

            StringBuilder sb = new StringBuilder();
            foreach (string key in Params.Keys)
            {
                sb.AppendFormat("{0}={1}&", key, HttpUtility.UrlEncode( Params[key]));
            }
            _pf.RequestString = sb.ToString();
        }

        public PagingFeature Parameter
        {
            get
            {
                return _pf;
            }
        }
    }
}